{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Shuffle String"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #array #string"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数组 #字符串"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: restoreString"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #重新排列字符串"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个字符串 <code>s</code> 和一个 <strong>长度相同</strong> 的整数数组 <code>indices</code> 。</p>\n",
    "\n",
    "<p>请你重新排列字符串 <code>s</code> ，其中第 <code>i</code> 个字符需要移动到 <code>indices[i]</code> 指示的位置。</p>\n",
    "\n",
    "<p>返回重新排列后的字符串。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<p><img alt=\"\" src=\"https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2020/07/26/q1.jpg\" /></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>s = \"codeleet\", <code>indices</code> = [4,5,6,7,0,2,1,3]\n",
    "<strong>输出：</strong>\"leetcode\"\n",
    "<strong>解释：</strong>如图所示，\"codeleet\" 重新排列后变为 \"leetcode\" 。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>s = \"abc\", <code>indices</code> = [0,1,2]\n",
    "<strong>输出：</strong>\"abc\"\n",
    "<strong>解释：</strong>重新排列后，每个字符都还留在原来的位置上。\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>s.length == indices.length == n</code></li>\n",
    "\t<li><code>1 &lt;= n &lt;= 100</code></li>\n",
    "\t<li><code>s</code> 仅包含小写英文字母</li>\n",
    "\t<li><code>0 &lt;= indices[i] &lt;&nbsp;n</code></li>\n",
    "\t<li><code>indices</code> 的所有的值都是 <strong>唯一</strong> 的</li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [shuffle-string](https://leetcode.cn/problems/shuffle-string/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [shuffle-string](https://leetcode.cn/problems/shuffle-string/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['\"codeleet\"\\n[4,5,6,7,0,2,1,3]', '\"abc\"\\n[0,1,2]']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "        return \"\".join(l[1] for l in sorted(zip(indices, s)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "        l = [0] * len(s)\n",
    "        for i in indices:\n",
    "            l[indices[i]] = s[i]\n",
    "        return ''.join(l)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "        dic=dict()\n",
    "        for i in range(len(s)):\n",
    "            dic[indices[i]]=s[i]\n",
    "        ans=''\n",
    "        for x in sorted(indices):\n",
    "            ans+=dic[x]\n",
    "        return  ans\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "        res = [\"\"] * len(indices)\n",
    "        for i, v in enumerate(s):\n",
    "            res[indices[i]] = s[i]\n",
    "        return \"\".join(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "        n = len(s)\n",
    "        ans = [\"\"] * n\n",
    "        for i, x in enumerate(indices):\n",
    "            ans[x] = s[i]\n",
    "        return \"\".join(ans)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "        new_dict = dict(zip(indices,s))\n",
    "        ans = \"\"\n",
    "        for i in range(len(indices)):\n",
    "            ans+=new_dict[i]\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "        return \"\".join([i[1]for i in sorted([(indices[i],s[i])for i in range(len(s))])])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "        res = [\"\" for i in range(len(s))]\n",
    "        for i in range(len(s)):\n",
    "            res[indices[i]] = s[i]\n",
    "        return \"\".join(res)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "        ans = [0]*len(indices)\n",
    "        for i in range(len(indices)):\n",
    "            ans[indices[i]] = s[i]\n",
    "        return ''.join(ans)\n",
    "\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "        resultList = [0] * len(indices)\n",
    "\n",
    "        strlist = list(s)\n",
    "\n",
    "        for i in range(len(strlist)):\n",
    "            resultList[indices[i]] = strlist[i]\n",
    "        \n",
    "        return \"\".join(resultList)\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "        res = [0]*len(s)\n",
    "        for i,j in zip(indices,s):\n",
    "            res[i] = j\n",
    "        return ''.join(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "        res=['']*len(s)\n",
    "        for i,x in enumerate(s):\n",
    "            res[indices[i]]=x\n",
    "        return \"\".join(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "        return ''.join([_ for i, _ in sorted(zip(indices, s))])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "        return \"\".join([c[1] for c in sorted(zip(indices, s))])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "        n = len(s)\n",
    "        ans = [\"\" for _ in range(n)]\n",
    "        for i in range(n):\n",
    "            ans[indices[i]] = s[i]\n",
    "        return \"\".join(ans)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "        return \"\".join([i[1] for i in sorted([(indices[i], s[i]) for i in range(len(s))])])\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self,s, indices):\n",
    "        ls = list(s)\n",
    "        for index,item in enumerate(s):\n",
    "            ls[indices[index]] = item\n",
    "        return ''.join(ls)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "        ans = ['']*len(s)\n",
    "        for i in range(len(s)):\n",
    "            ans[indices[i]] = s[i]\n",
    "        return ''.join(ans)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "        table = [x for x in zip(indices, s)]\n",
    "        table.sort(key = lambda x: x[0])\n",
    "        return ''.join(x[1] for x in table)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "        n = len(s)\n",
    "        ret = [''] * n\n",
    "        for i in range(n):\n",
    "            ret[indices[i]] = s[i]\n",
    "        return ''.join(ret)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "        ans = list(s)\n",
    "        for i, index in enumerate(indices):\n",
    "            ans[index] = s[i]\n",
    "        return ''.join(ans)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "        m = len(s)\n",
    "        new_str = ['' for i in range(m)]\n",
    "        for i in range(m):\n",
    "            new_str[indices[i]] = s[i]\n",
    "        return ''.join(new_str)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "          dic={}\n",
    "          string=''\n",
    "          for i in range(len(indices)):\n",
    "           dic[indices[i]]=s[i]\n",
    "          for i in range(len(dic)):\n",
    "                string+=dic[i]\n",
    "          return string"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "import copy\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "        result = list(copy.deepcopy(s))\n",
    "        res = str()\n",
    "        for i in range(len(s)):\n",
    "            print(s[indices[i]])\n",
    "            result[indices[i]] = s[i]\n",
    "        for i in result:\n",
    "            res += i\n",
    "\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "        ans = [0]*len(s)\n",
    "        for i, c in enumerate(indices):\n",
    "            ans[c] = s[i]\n",
    "        return ''.join(ans)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "        ans = [''] * len(s)\n",
    "        for x, i in zip(s, indices):\n",
    "            ans[i] = x\n",
    "        return \"\".join(ans)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "        n = len(s)\n",
    "        ret = [''] * n\n",
    "        for i in range(0 , n):\n",
    "            ret[indices[i]] = s[i]\n",
    "        return \"\".join(ret)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "        tstr='';\n",
    "        for index in range(len(indices)):\n",
    "            tindex=indices.index(index);\n",
    "            tstr+=s[tindex];\n",
    "        return tstr;\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "      ans = []\n",
    "      for x in s:\n",
    "        ans.append(x)\n",
    "      i = 0\n",
    "      while i < len(indices):\n",
    "        j = indices[i]\n",
    "        if j != i:\n",
    "          ans[i], ans[j] = ans[j], ans[i]\n",
    "          indices[i], indices[j] = indices[j], indices[i]\n",
    "        else:\n",
    "          i += 1\n",
    "      return ''.join(ans)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "          res = [\"\" for i in range(len(s))]\n",
    "          for i in range(len(s)):\n",
    "            res[indices[i]] = s[i]\n",
    "          return \"\".join(res)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "        l = len(s)\n",
    "        res = ['_'] * l\n",
    "        for i in range(l):\n",
    "            res[indices[i]] = s[i]\n",
    "        return ''.join(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "        length = len(s)\n",
    "        result = [\"\"] * length\n",
    "        for i, ch in enumerate(s):\n",
    "            result[indices[i]] = ch\n",
    "        return \"\".join(result)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "        ds = {indices[i]:s[i] for i in range(len(s))}\n",
    "        out = ''\n",
    "        for i in sorted(ds.keys()):\n",
    "            out += ds[i]\n",
    "        return out"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "        res = [\"\"for _ in range(len(s))]\n",
    "        for(item,index) in zip(s,indices):\n",
    "            res[index] = item\n",
    "        return \"\".join(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "        n = len(s)\n",
    "        ans = [\"\"]*n\n",
    "        for i, x in enumerate(s):\n",
    "            ans[indices[i]] = x\n",
    "        return \"\".join(ans)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "        smap = list(zip(s,indices))\n",
    "        smap.sort(key=lambda x:x[1])\n",
    "        ans,_ = zip(*smap)\n",
    "        return ''.join(ans)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "        l=[0]*len(indices)\n",
    "        for i,ss in enumerate(indices):\n",
    "            l[ss]=s[i]\n",
    "        return ''.join(l)\n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "      ans = [''] * len(s)\n",
    "      for i, ch in enumerate(s):\n",
    "        ans[indices[i]] = ch\n",
    "      return ''.join(ans)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "\n",
    "        n = len(indices)\n",
    "        ans = [0] * n\n",
    "        ss = ''\n",
    "        for i in range(n):\n",
    "            ans[indices[i]] = s[i]\n",
    "        for i in range(n):\n",
    "            ss += ans[i]\n",
    "\n",
    "        return ss"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "        return \"\".join([i[1] for i in sorted([(indices[i], s[i]) for i in range(len(s))])])\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "        d=[]\n",
    "        for i in range(len(indices)):\n",
    "            a=indices.index(i)\n",
    "            d.append(s[a])\n",
    "        return ''.join(d)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "        res = [0] * len(s)\n",
    "        for i in range(len(s)):\n",
    "            res[indices[i]] = s[i]\n",
    "        return ''.join(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "        ans = ['0'] * len(indices)\n",
    "        for x, y in enumerate(indices):\n",
    "            ans[y] = s[x]\n",
    "        return \"\".join(ans)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "        dic = dict()\n",
    "        for i in range(len(s)):\n",
    "            dic[indices[i]]=s[i]\n",
    "        ans = ''\n",
    "        for i in range(len(s)):\n",
    "            ans += dic[i]\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "       n=len(indices)\n",
    "       ans=[\"\"]*n\n",
    "       for a,b in enumerate(s):\n",
    "           ans[indices[a]]=b\n",
    "       return \"\".join(ans)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "        # x = ''\n",
    "        # for i in range(len(s)):\n",
    "        #     x += s[indices.index(i)]\n",
    "        return ''.join([s[indices.index(i)] for i in range(len(s))])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "        n=len(s)\n",
    "        res=[0]*n\n",
    "        for i in range(n):\n",
    "            res[indices[i]]=s[i]\n",
    "        print(res)\n",
    "        return ''.join(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "\n",
    "        n = len(indices)\n",
    "        ans = [0] * n\n",
    "        ss = ''\n",
    "        for i in range(n):\n",
    "            ans[indices[i]] = s[i]\n",
    "        for i in range(n):\n",
    "            ss += ans[i]\n",
    "\n",
    "        return ss"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "        length = len(s)\n",
    "        result = [\"\"] * length\n",
    "        for i, ch in enumerate(s):\n",
    "            result[indices[i]] = ch\n",
    "        return \"\".join(result)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "        res=[0]*len(indices)\n",
    "        for i in range(len(indices)):\n",
    "            res[indices[i]]=s[i]\n",
    "        return \"\".join(res)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "        lenth = len(s)\n",
    "        res = [\"\"]*lenth\n",
    "        for i, v in enumerate(s):\n",
    "            res[indices[i]] = v\n",
    "        \n",
    "        return \"\".join(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "        if not s: return ''\n",
    "        res = list(s)\n",
    "        for i in range(len(s)):\n",
    "            res[indices[i]] = s[i]\n",
    "        return ''.join(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from typing import List\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "        slist = []\n",
    "        for i in range(len(indices)):\n",
    "            slist.append([indices[i], s[i]])\n",
    "        slist.sort(key=lambda x: x[0])\n",
    "        res = []\n",
    "        for si in slist:\n",
    "            res.append(str(si[1]))\n",
    "        # return str(res)\n",
    "        return \"\".join(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "        arrange, output = 0, ''\n",
    "        for i in range(len(s)):\n",
    "            for curr in range(len(s)):\n",
    "                if arrange == indices[curr]:\n",
    "                    output += s[curr]\n",
    "                    arrange += 1\n",
    "                    break\n",
    "        return output"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "        s=[i for i in s]\n",
    "        list1=[0]*len(s)\n",
    "        for i,j in zip(s,indices):\n",
    "            list1[j]=i \n",
    "        return ''.join(list1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "        newStr = \"\"\n",
    "        for i in indices:\n",
    "            newStr = newStr + \"i\"\n",
    "\n",
    "        newStr = list(newStr)\n",
    "        for i,item in enumerate(indices):\n",
    "            newStr[item] = s[i]\n",
    "\n",
    "        res = \"\"\n",
    "        for item in newStr:\n",
    "            res = res + item\n",
    "\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "        n=len(indices)\n",
    "        ans=[\"\"]*n\n",
    "        for a,b in enumerate(s):\n",
    "            ans[indices[a]]=b\n",
    "        return \"\".join(ans)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "        anw = [\"\" for i in range(len(s))]\n",
    "        for i in range(len(s)):\n",
    "            anw[indices[i]] = s[i]\n",
    "        return \"\".join(anw)\n",
    "\n",
    "\\"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "        res = ['null']*len(s)\n",
    "        cou = 0\n",
    "        for i in indices:\n",
    "            res[i] = s[cou]\n",
    "            cou +=1\n",
    "        return ''.join(res)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "        return ''.join([dict(zip(indices, s))[i] for i in range(len(s))])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def restoreString(self, s: str, indices: List[int]) -> str:\n",
    "        s1 = [''] * len(s)\n",
    "\n",
    "        for i, n in enumerate(indices):\n",
    "            s1[n] = s[i]\n",
    "        return \"\".join(s1)"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
